package org.springblade.modules.auth.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: 微信特殊字符处理工具
 * @author: luoyt
 * @create: 2024-08-25 15:30
 **/
public class EmojiStringUtils {

    /**
     * 判断是否存在特殊字符串
     * @param content
     * @return
     */
    public static boolean hasEmoji(String content){
        Pattern pattern = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]");
        Matcher matcher = pattern.matcher(content);
        if(matcher .find()){
            return true;
        }
        return false;
    }

    /**
     * 替换字符串中的emoji字符
     * @param str
     * @return
     */
    public static String replaceEmoji(String str){
        if(!hasEmoji(str)){
            return str;
        }else{
            str=str.replaceAll("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", " ");
            return str;
        }

    }
}